Shader "Hidden/PVS/ObjectId"
{
    SubShader
    {
        Tags{ "RenderType"="Opaque" "Queue"="Geometry" }
        Pass
        {
            ZWrite On ZTest LEqual Cull Back
            HLSLPROGRAM
            #pragma target 3.5
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            // 注意：用 int 更容易通过 MPB 赋值
            int _ObjectId;

            struct appdata { float4 vertex:POSITION; };
            struct v2f      { float4 pos:SV_POSITION; };

            v2f vert(appdata v){ v2f o; o.pos = UnityObjectToClipPos(v.vertex); return o; }

            float4 frag(v2f i):SV_Target
            {
                uint id = (uint)_ObjectId;
                // 把 32bit 整数打包到 RGBA [0..1]（每通道 8bit）
                float4 c;
                c.r = (id & 0xFFu) / 255.0;
                c.g = ((id >> 8u) & 0xFFu) / 255.0;
                c.b = ((id >> 16u)& 0xFFu) / 255.0;
                c.a = ((id >> 24u)& 0xFFu) / 255.0;
                return c;
            }
            ENDHLSL
        }
    }
    Fallback Off
}
